package controller.servletCadastro;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.classDAO.EnderecoFuncionarioDAO;
import model.classes.EnderecoFuncionario;
import model.factory.FactoryDAO;

/**
 * Servlet implementation class ServletCadastroEnderecoFuncionario
 */
@WebServlet("/ServletCadastroEnderecoFuncionario")
public class ServletCadastroEnderecoFuncionario extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletCadastroEnderecoFuncionario() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher rd = null;
		String rua = request.getParameter("rua");
		String bairro = request.getParameter("bairro");
		String numero = request.getParameter("numero");
        String cep = request.getParameter("cep");
        String cidade = request.getParameter("cidade");
        String estado = request.getParameter("estado");
		
		EnderecoFuncionario ef = new EnderecoFuncionario();
        
		int num = 0;
 		if( numero != null || !numero.equals("") || numero.equals("0"))
 			num = Integer.parseInt(numero);
 		
 		ef.setRua(rua);
 		ef.setBairro(bairro);
 		ef.setNumero(num);
 		ef.setCep(cep);
 		ef.setCidade(cidade);
 		ef.setEstado(estado);
 		
 		EnderecoFuncionarioDAO efDAO = FactoryDAO.getEnderecoFuncionarioDAO();
 		efDAO.cadastrar(ef);
 		
 		rd = request.getRequestDispatcher("/index.jsp");
		rd.forward(request, response);
	}

}
